package logic

import (
	"context"
	"renting-demo/house_srv/house"

	"renting-demo/api/internal/svc"
	"renting-demo/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateHouseLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateHouseLogic {
	return &CreateHouseLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateHouseLogic) CreateHouse(req *types.CreateHouseRequest) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.HouseServe.Create(context.Background(), &house.CreateHouseRequest{
		HouseSize:        float32(req.HouseSize),
		Text:             req.Text,
		HouseLocal:       req.HouseLocal,
		AddressId:        req.AddressId,
		Price:            float32(req.Price),
		CharacteristicId: req.CharacteristicId,
	})
	if res.Status == "0" {
		return &types.Data{
			Code:    200,
			Message: "房源创建成功",
		}, nil
	}
	return &types.Data{
		Code:    200,
		Message: "房源创建成功",
	}, nil
}
